<!-- Bot Console -->
<!-- Author: Edwin -->
<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class='bot-console'>
      <el-row>
        <el-col :span="24">
          <!-- <div class="line-height: 1.15; height: 3em; border-bottom: 3px solid #333;">{{botInfo.name}}</div> -->
          <el-card shadow="never"
                   class="aui-card--fill"
                   style="margin-bottom: 14px;">
            <el-form label-width="120px">
              <el-form-item :label="$t('custom.botStore.console.name')">
                <el-input v-model="botInfo.name"
                          :disabled="true"
                          :placeholder="$t('custom.botStore.console.inputNamePlaceholder')"></el-input>
              </el-form-item>
              <el-form-item :label="$t('custom.botStore.console.description')">
                <el-input v-model="botInfo.description"
                          :disabled="true"
                           :placeholder="$t('custom.botStore.console.inputDescriptionPlaceholder')"></el-input>
              </el-form-item>
              <el-form-item :label="$t('custom.botStore.console.version')">
                <el-input v-model="botInfo.version"
                          :disabled="true"
                          :placeholder="$t('custom.botStore.console.inputVersionPlaceholder')"></el-input>
              </el-form-item>
            </el-form>
            <el-form inline
                     label-width="120px">
              <el-form-item :label="$t('custom.botStore.console.enable')"
                            style="marginBottom:0;">
                <el-switch v-model="botInfo.enable"
                           :disabled="true"></el-switch>
              </el-form-item>
              <el-form-item :label="$t('custom.botStore.console.applyToClient')">
                <el-switch v-model="botInfo.apply"
                           :disabled="true"></el-switch>
              </el-form-item>
            </el-form>
            <el-form label-width="120px">
              <el-form-item :label="$t('custom.botStore.console.integration')"
                            style="marginBottom:0;">
                <el-select v-model="botInfo.subjectCode">
                  <el-option v-for="e in integrationList"
                             :key="e.subjectCode"
                             :label="e.name"
                             :value="e.subjectCode"></el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>
      </el-row>
      <!-- Cancel Action and ConnectorConfig -->
      <!-- <el-row :gutter="10">
        <el-col :span="6">
          <PageBox linkComponent='Action' />
        </el-col>
        <el-col :span="18">
          <PageBox linkComponent='ConnectorConfig' />
        </el-col>
      </el-row> -->
      <el-row>
        <el-col :span="24">
          <PageBox linkComponent='Functions'
                   :boxData="botInfo" />
        </el-col>
      </el-row>
      <!-- Cancel Message Report -->
      <!-- <el-row>
      <el-col :span="24">
        <PageBox linkComponent='MessageReport' />
      </el-col>
    </el-row> -->
    </div>
  </el-card>
</template>

<script>
import PageBox from './BotConsoleComponents/page-box'

export default {
  components: { PageBox },
  data () {
    return {
      botInfo: {
        id: '',
        name: '',
        icon: null,
        description: '',
        enable: true,
        url: null,
        version: '1.0',
        createTime: null,
        updateTime: null,
        applyTenant: false,
        // tenantCode: '',
        // sysVersion: '1.0',
        // sysBotId: '',
        // sysEnable: true
        subjectCode: null
      },
      integrationList: []
    }
  },
  created () {
    this.botInfo.id = this.$route.query.id
    this.init()
    this.getIntegrationList()
  },
  methods: {
    init () {
      this.$interface.botStore.getTenantBotInfoApi({ id: this.botInfo.id })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.botInfo = res.data
        }).catch(() => { })
    },
    getIntegrationList () {
      const params = {
        tenantCode: this.$store.state.user.tenantCode,
        loadType: 3
      }
      return this.$interface.taskManager.getConnectorInfoNew(params)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          let mapObj = res.data
          let tempList = []
          for (let key in mapObj) {
            tempList.push({
              name: mapObj[key].name,
              subjectCode: mapObj[key].sync.subjectCode,
              status: mapObj[key].sync.status
            })
          }
          this.integrationList = tempList
        })
        .catch(() => { })
    },
    changeBotIntegration () {
      const params = {
        systemBotIds: this.botInfo.id,
        subjectCode: this.botInfo.subjectCode
      }
      this.$interface.botStore.updateBotIntegrationApi(params)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message.success(res.msg)
        })
        .catch(() => { })
    }
  }
}
</script>

<style scoped>
.c-usage-content {
  border-radius: 4px;
  border-width: 0px;
  left: 90px;
  top: 153px;
  width: 553px;
  height: 129px;
}
</style>
